<?php 
class SslComponent extends Object {
	
	var $components = array('RequestHandler');
	
	var $Controller = null;
	
	function initialize(&$Controller) {
		$this->Controller = $Controller;
	}
	
	function force_ssl() {
		if(!$this->RequestHandler->isSSL()) {
			$this->Controller->redirect('https://'.$this->__url('ssl'));
		}
	}

	function force_nossl() {
		if($this->RequestHandler->isSSL()) {
			$this->Controller->redirect('http://'.$this->__url('nossl'));
		}		
	}

	function __url($direction = null) {
		//$port = env('SERVER_PORT') == 80 ? '' : ':'.env('SERVER_PORT');

		$port = '';

		return env('SERVER_NAME').$port.env('REQUEST_URI');
		// return env('SERVER_NAME').$port.env('REQUEST_URI');
	}
}
?>